package com.kujie.config;

import org.springframework.ai.chat.client.advisor.SafeGuardAdvisor;
import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
import org.springframework.ai.rag.advisor.RetrievalAugmentationAdvisor;
import org.springframework.ai.rag.generation.augmentation.ContextualQueryAugmenter;
import org.springframework.ai.rag.retrieval.search.VectorStoreDocumentRetriever;
import org.springframework.ai.vectorstore.milvus.MilvusVectorStore;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * 顾问配置
 *
 * @author check
 * @date 2025-07-26
 */
@Configuration
public class AdvisorConfig {

//    /**
//     * 检索增强顾问
//     *
//     * @param milvusVectorStore 矢量存储
//     * @return RetrievalAugmentationAdvisor
//     */
//    @Bean
//    public RetrievalAugmentationAdvisor advisorAdvisor(MilvusVectorStore milvusVectorStore) {
//        return RetrievalAugmentationAdvisor.builder()
//                .documentRetriever(VectorStoreDocumentRetriever.builder()
//                        .similarityThreshold(0.50)
//                        .vectorStore(milvusVectorStore)
//                        .build())
//                .queryAugmenter(ContextualQueryAugmenter.builder()
//                        .allowEmptyContext(true)
//                        .build())
//                .build();
//    }

    /**
     * 日志顾问
     *
     * @return SimpleLoggerAdvisor
     */
    @Bean
    public SimpleLoggerAdvisor simpleLoggerAdvisor() {
        return new SimpleLoggerAdvisor();
    }

//    /**
//     * 安全顾问，屏蔽敏感词
//     *
//     * @return SafeGuardAdvisor
//     */
//    @Bean
//    public SafeGuardAdvisor safeGuardAdvisor() {
//        List<String> words = new ArrayList<>();
//        InputStream inputStream = getClass().getClassLoader().getResourceAsStream("template/sensitive.txt");
//        if (inputStream == null) {
//            throw new IllegalArgumentException("文件未找到: " + "sensitive.txt");
//        }
//
//        try (Scanner scanner = new Scanner(inputStream)) {
//            while (scanner.hasNextLine()) {
//                words.add(scanner.nextLine());
//            }
//        }
//        return new SafeGuardAdvisor(words);
//    }
}
